package sys_runtime

import (
	"encoding/json"
	"fmt"
	sys_config "go-iot-gateway/internal/sys/config"
	"runtime"
	"time"
)

var startingTime = time.Now()

type SysRunningInfo struct {
	StartingTime time.Time
}

//func init() {
//	startingTime = time.Now()
//}

// StartingTime 获取系统启动时间
func StartingTime() time.Time {
	return startingTime
}

func Setting(sysConfig *sys_config.SysConfigInfo) {
	env := sysConfig.System

	fmt.Printf("\n ===== 初始化SYS ===== \n")
	jsonData, _ := json.Marshal(env)
	fmt.Printf("%s \n", string(jsonData))

	//将同时运行的goroutine数量设置为1，每100MB采一次样，最大堆内存为1GB
	//默认每个 goroutine 占用 8KB 内存
	if env.GoMaxProcs > 0 {
		runtime.GOMAXPROCS(env.GoMaxProcs)
	}

	if env.Stack > 0 {
		//todo
		//runtime.Stack()
	}

	//os.Setenv("GOGC", "500")
	//os.Setenv("GODEBUG", "gctrace=1")

	//时区设置
	var cstZone = time.FixedZone("CST", 8*3600) // 东八
	time.Local = cstZone
}
